﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PO_2011;

namespace WindowsFormsApplication1
{
    public partial class BrightnessWindow : Form
    {

        private Pnm p;
        public Form1 refToMainWindow;
        float value = 0;
        private Bitmap actualBitmap;
        bool wasApply = false;

        public BrightnessWindow(Pnm objectPnm, Bitmap bitmap)
        {
            InitializeComponent();
            p = objectPnm;
            actualBitmap = bitmap;

        }


        private void okButton_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.BitmapTB;
            p.Bitmap = p.BitmapTB;
            wasApply = true;
            this.Close();
        }

        private void resetButton_Click(object sender, EventArgs e)
        {
            brightnessTrackBar.Value = 10;
            this.brightnessTrackBar_ValueChanged(sender, e);
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.CopyBitmap;
            this.Close();
        }

        private void BrightnessWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(!wasApply) this.refToMainWindow.pictureBox1.Image = p.CopyBitmap;
        }

        private void brightnessTrackBar_ValueChanged(object sender, EventArgs e)
        {
                value = brightnessTrackBar.Value;
                p.changeBrightness(value, actualBitmap);
                this.refToMainWindow.pictureBox1.Image = p.BitmapTB;
        }








    }
}
